1
|
|
|
/* |
2
|
|
|
* Copyright (C) 2021 Joe Nilson <[email protected]> |
3
|
|
|
* |
4
|
|
|
* This program is free software: you can redistribute it and/or modify |
5
|
|
|
* it under the terms of the GNU Lesser General Public License as |
6
|
|
|
* published by the Free Software Foundation, either version 3 of the |
7
|
|
|
* License, or (at your option) any later version. |
8
|
|
|
* |
9
|
|
|
* This program is distributed in the hope that it will be useful, |
10
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
11
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12
|
|
|
* GNU Lesser General Public License for more details. |
13
|
|
|
* You should have received a copy of the GNU Lesser General Public License |
14
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
15
|
|
|
*/ |
16
|
|
|
function businessDocViewSubjectChanged() |
17
|
|
|
{ |
18
|
|
|
var data = {}; |
19
|
|
|
$.each($("#" + businessDocViewFormName).serializeArray(), function (key, value) { |
|
|
|
|
20
|
|
|
data[value.name] = value.value; |
21
|
|
|
}); |
22
|
|
|
data.action = "subject-changed"; |
23
|
|
|
logConsole(data, "subject-changed"); |
24
|
|
|
|
25
|
|
|
$.ajax({ |
26
|
|
|
type: "POST", |
27
|
|
|
url: businessDocViewUrl, |
|
|
|
|
28
|
|
|
dataType: "json", |
29
|
|
|
data: data, |
30
|
|
|
success: function (results) { |
31
|
|
|
$("#doc_codpago").val(results.codpago); |
32
|
|
|
$("#doc_codserie").val(results.codserie); |
33
|
|
|
$("#formEditFacturaProveedor select[name=ncftipopago]").val(results.ncftipopago); |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Review the doc_codsubtipodoc existence, |
37
|
|
|
* if it exist we put the value from the customer data |
38
|
|
|
*/ |
39
|
|
|
if ($("#doc_codsubtipodoc").length !== 0) { |
40
|
|
|
$("#doc_codsubtipodoc").val(results.codsubtipodoc); |
41
|
|
|
} |
42
|
|
|
logConsole(results.codsubtipodoc,"codsubtipodoc"); |
43
|
|
|
/** |
44
|
|
|
* Review the doc_codopersaciondoc existence, |
45
|
|
|
* if it exist we put the value from the customer data |
46
|
|
|
*/ |
47
|
|
|
if ($("#doc_codoperaciondoc").length !== 0) { |
48
|
|
|
$("#doc_codoperaciondoc").val(results.codoperaciondoc); |
49
|
|
|
} |
50
|
|
|
logConsole(results.codoperaciondoc,"codoperaciondoc"); |
51
|
|
|
|
52
|
|
|
logConsole(results,"results"); |
53
|
|
|
|
54
|
|
|
businessDocViewRecalculate(); |
55
|
|
|
}, |
56
|
|
|
error: function (xhr, status, error) { |
|
|
|
|
57
|
|
|
alert(xhr.responseText); |
|
|
|
|
58
|
|
|
} |
59
|
|
|
}); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
async function cargarTipoPago() |
63
|
|
|
{ |
64
|
|
|
return $.ajax({ |
65
|
|
|
url: 'ListNCFTipoPago', |
66
|
|
|
async: true, |
67
|
|
|
data: {'action': 'busca_pago', 'tipopago': '02'}, |
68
|
|
|
type: 'POST', |
69
|
|
|
datatype: 'json', |
70
|
|
|
success: function (response) { |
71
|
|
|
let data = JSON.parse(response); |
72
|
|
|
return data; |
73
|
|
|
}, |
74
|
|
|
error: function (xhr, status) { |
75
|
|
|
alert('Ha ocurrido algún tipo de error ' + status); |
|
|
|
|
76
|
|
|
} |
77
|
|
|
}); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
async function cargarTipoMovimiento() |
81
|
|
|
{ |
82
|
|
|
return $.ajax({ |
83
|
|
|
url: 'ListNCFTipoMovimiento', |
84
|
|
|
async: true, |
85
|
|
|
data: {'action': 'busca_movimiento', 'tipomovimiento': 'COM'}, |
86
|
|
|
type: 'POST', |
87
|
|
|
datatype: 'json', |
88
|
|
|
success: function (response) { |
89
|
|
|
let data = JSON.parse(response); |
90
|
|
|
return data; |
91
|
|
|
}, |
92
|
|
|
error: function (xhr, status) { |
93
|
|
|
alert('Ha ocurrido algún tipo de error ' + status); |
|
|
|
|
94
|
|
|
} |
95
|
|
|
}); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
async function businessDocViewSave() |
99
|
|
|
{ |
100
|
|
|
$("#btn-document-save").prop("disabled", true); |
101
|
|
|
|
102
|
|
|
var tipoPago = await cargarTipoPago(); |
103
|
|
|
var datosPago = JSON.parse(tipoPago); |
104
|
|
|
var ncfTipoPagoCliente = $("#formEditFacturaProveedor select[name=ncftipopago]").val(); |
105
|
|
|
var readOnlySelects = ($("#formPurchaseDocumentLine #doc_idestado").val() === '11'); |
106
|
|
|
let selectOptionsPagos = ""; |
107
|
|
View Code Duplication |
$.each(datosPago.pagos, function(i, value) { |
|
|
|
|
108
|
|
|
let defaultSelected = ((value.codigo === '04' && ncfTipoPagoCliente === '') || ncfTipoPagoCliente === value.codigo) ? 'selected' : ''; |
109
|
|
|
let noSelected = ($("#formPurchaseDocumentLine #doc_idestado").val() === '11' && defaultSelected !== 'selected') ? ' disabled' : ''; |
110
|
|
|
selectOptionsPagos += '<option value="'+value.codigo+'"'+defaultSelected+noSelected+'>'+value.descripcion+'</option>'; |
111
|
|
|
}); |
112
|
|
|
|
113
|
|
|
var tipoMovimiento = await cargarTipoMovimiento(); |
114
|
|
|
var datosMovimiento = JSON.parse(tipoMovimiento); |
115
|
|
|
|
116
|
|
|
let selectOptionsMovimientos = ""; |
117
|
|
View Code Duplication |
$.each(datosMovimiento.movimientos, function (i, value) { |
|
|
|
|
118
|
|
|
let defaultSelected = (value.codigo === '09') ? 'selected' : ''; |
119
|
|
|
let noSelected = ($("#formPurchaseDocumentLine #doc_idestado").val() === '11' && defaultSelected !== 'selected') ? ' disabled' : ''; |
120
|
|
|
selectOptionsMovimientos += '<option value="'+value.codigo+'"'+defaultSelected+noSelected+'>'+value.descripcion+'</option>'; |
121
|
|
|
}); |
122
|
|
|
|
123
|
|
|
let message = '<div class="form-content">\n' + |
124
|
|
|
' <form class="form" role="form">\n' + |
125
|
|
|
' <div class="form-group">\n' + |
126
|
|
|
' <label for="ncftipopago">Tipo de Pago</label>\n' + |
127
|
|
|
' <select class="custom-select" id="ncftipopago" name="ncftipopago"'+readOnlySelects+'>\n' + |
128
|
|
|
selectOptionsPagos + |
129
|
|
|
' </select>\n' + |
130
|
|
|
' </div>\n' + |
131
|
|
|
' <div class="form-group">\n' + |
132
|
|
|
' <label for="ncftipomovimiento">Tipo de Movimiento</label>\n' + |
133
|
|
|
' <select class="custom-select" id="ncftipomovimiento" name="ncftipomovimiento"'+readOnlySelects+'>\n' + |
134
|
|
|
selectOptionsMovimientos + |
135
|
|
|
' </select>\n' + |
136
|
|
|
' </div>\n' + |
137
|
|
|
' </form>\n' + |
138
|
|
|
' </div>'; |
139
|
|
|
|
140
|
|
|
executeModal( |
141
|
|
|
'completeNCFData', |
142
|
|
|
'Complete la información faltante', |
143
|
|
|
message, |
144
|
|
|
'default', |
145
|
|
|
'saveBussinessDocument' |
146
|
|
|
); |
147
|
|
|
|
148
|
|
|
// bootbox.dialog({ |
149
|
|
|
// title: "Complete la información faltante", |
150
|
|
|
// message: '<div class="form-content">\n' + |
151
|
|
|
// ' <form class="form" role="form">\n' + |
152
|
|
|
// ' <div class="form-group">\n' + |
153
|
|
|
// ' <label for="ncftipopago">Tipo de Pago</label>\n' + |
154
|
|
|
// ' <select class="custom-select" id="ncftipopago" name="ncftipopago"'+readOnlySelects+'>\n' + |
155
|
|
|
// selectOptionsPagos + |
156
|
|
|
// ' </select>\n' + |
157
|
|
|
// ' </div>\n' + |
158
|
|
|
// ' <div class="form-group">\n' + |
159
|
|
|
// ' <label for="ncftipomovimiento">Tipo de Movimiento</label>\n' + |
160
|
|
|
// ' <select class="custom-select" id="ncftipomovimiento" name="ncftipomovimiento"'+readOnlySelects+'>\n' + |
161
|
|
|
// selectOptionsMovimientos + |
162
|
|
|
// ' </select>\n' + |
163
|
|
|
// ' </div>\n' + |
164
|
|
|
// ' </form>\n' + |
165
|
|
|
// ' </div>', |
166
|
|
|
// buttons: [ |
167
|
|
|
// { |
168
|
|
|
// label: "Guardar", |
169
|
|
|
// className: "btn btn-primary", |
170
|
|
|
// callback: function() { |
171
|
|
|
// var data = {}; |
172
|
|
|
// $.each($("#" + businessDocViewFormName).serializeArray(), function (key, value) { |
173
|
|
|
// data[value.name] = value.value; |
174
|
|
|
// }); |
175
|
|
|
// data['ncftipopago'] = $('form #ncftipopago').val(); |
176
|
|
|
// data['ncftipomovimiento'] = $('form #ncftipomovimiento').val(); |
177
|
|
|
// data.action = "save-document"; |
178
|
|
|
// data.lines = getGridData(); |
179
|
|
|
// |
180
|
|
|
// $.ajax({ |
181
|
|
|
// type: "POST", |
182
|
|
|
// url: businessDocViewUrl, |
183
|
|
|
// dataType: "text", |
184
|
|
|
// data: data, |
185
|
|
|
// success: function (results) { |
186
|
|
|
// if (results.substring(0, 3) === "OK:") { |
187
|
|
|
// $("#" + businessDocViewFormName + " :input[name=\"action\"]").val('save-ok'); |
188
|
|
|
// $("#" + businessDocViewFormName).attr('action', results.substring(3)).submit(); |
189
|
|
|
// } else { |
190
|
|
|
// alert(results); |
191
|
|
|
// $("#" + businessDocViewFormName + " :input[name=\"multireqtoken\"]").val(randomString(20)); |
192
|
|
|
// } |
193
|
|
|
// }, |
194
|
|
|
// error: function (msg) { |
195
|
|
|
// alert(msg.status + " " + msg.responseText); |
196
|
|
|
// } |
197
|
|
|
// }); |
198
|
|
|
// |
199
|
|
|
// } |
200
|
|
|
// }, |
201
|
|
|
// { |
202
|
|
|
// label: "Cancelar", |
203
|
|
|
// className: "btn btn-danger", |
204
|
|
|
// callback: function() { |
205
|
|
|
// return true; |
206
|
|
|
// } |
207
|
|
|
// } |
208
|
|
|
// ], |
209
|
|
|
// }); |
210
|
|
|
|
211
|
|
|
$("#btn-document-save").prop("disabled", false); |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
// $(document).ready(function () { |
215
|
|
|
// var ArrayTipoNCFCompras = ['11','12','16','17']; |
216
|
|
|
// if($("#doc_codsubtipodoc").val() !== '') { |
217
|
|
|
// verificarCorrelativoNCF($("#doc_codsubtipodoc").val()); |
218
|
|
|
// } |
219
|
|
|
// |
220
|
|
|
// $("#doc_codsubtipodoc").change(function() { |
221
|
|
|
// logConsole($("#doc_codsubtipodoc").val(),"#doc_codsubtipodoc val"); |
222
|
|
|
// if(ArrayTipoNCFCompras.includes($("#doc_codsubtipodoc").val())) { |
223
|
|
|
// verificarCorrelativoNCF($("#doc_codsubtipodoc").val()); |
224
|
|
|
// } |
225
|
|
|
// }); |
226
|
|
|
// }); |
227
|
|
|
|
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.